package com.lagou.flashsale.controller;

import com.lagou.flashsale.entity.Order;
import com.lagou.flashsale.entity.OrderStatus;
import com.lagou.flashsale.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;

    @RequestMapping(value = "/order", method = RequestMethod.POST)
    public String order(Order order) {
        // 设置订单状态为新建，未支付
        order.setOrderStatus(OrderStatus.NEW);
        boolean result = orderService.order(order);

        return result ? "success" : "fail";
    }

}
